<?php

class Fete_View_Helper_CurrentUrl extends Fete_View_Helper
{
    protected $_encoded = false;
    protected $_currentUrlEncoded = null;
    protected $_currentUrl = null;

    /**
     *
     * @param boolean $encoded
     * @return Fete_View_Helper_CurrentUrl
     */
    public function &currentUrl($encoded = false)
    {
        $this->_encoded = $encoded;

        if (null === $this->_currentUrl) {
            $this->_currentUrl = $_SERVER['REQUEST_URI'];
            $this->_currentUrlEncoded = urlencode($_SERVER['REQUEST_URI']);
        }

        return $this;
    }

    public function __toString()
    {
        if ($this->_encoded) {
            return $this->_currentUrlEncoded;
        }

        return $this->_currentUrl;
    }
}